// import { getCookie } from "../auth/script.js";

import { validNumberFromGet, showAlert } from "../functionFromexport.js";
import autosize from "../node_modules/autosize/src/autosize.js";

// const clientGroupId = getCookie("clientGroupId");
const clientGroupId = localStorage.getItem("clientGroupId");
// let phoneClient = getCookie("phoneNumber");
let phoneClient = localStorage.getItem("phoneNumber");
phoneClient = validNumberFromGet(phoneClient);

const radioPrev = document.getElementById("value-2");
const radioNext = document.getElementById("value-1");
const innerNextLesson = document.getElementById("innerNextLesson");
const innerPrevLesson = document.getElementById("innerPrevLesson");
const loadMoreNextButton = document.querySelector(".loadMoreNext");
const loadMorePrevButton = document.querySelector(".loadMorePrev");

let resourceIdFromGet = 0;
let startingIndex = 0;
let endingIndex = 5;
let prevLessonArr = [];
let NextLessonArr = [];

let BIGprevLessonArr = [];
let BIGNextLessonArr = [];

let flagActionCancelLesson = true;

const WebApp = window.Telegram.WebApp;
// WebApp.MainButton.text = "Готово";
// WebApp.MainButton.color = "#EE7A45";

WebApp.MainButton.setParams({
  text: "Готово",
  color: "#EE7A45",
});

let clientJson = {};

setTimeout(() => {
  fetch("/client", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      clientPhone: phoneClient,
    }),
  })
    .then((response) => response.json())
    .then((data) => {
      console.log("получил череz", data);
      clientJson = data;
    })
    .catch((err) => {
      console.log(err);
    });
}, 1000);

fetch("/nextlessons", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ clientGroupId: clientGroupId }),
})
  .then((res) => res.json())
  .then((data) => {
    console.log(data);
    console.log("nextlesson - и длинна", data.length >= 5);
    if (data.length >= 5) {
      loadMoreNextButton.classList.remove("classHide");
    }
    NextLessonArr = data;
    BIGNextLessonArr = data;
    displayAllNextLesson(data, NextLessonArr.slice(startingIndex, endingIndex));
    moveLesson(data);
    lateLesson(data);
  })
  .catch((err) => {
    console.log(err);
  });

setTimeout(() => {
  if (radioNext.checked) {
    loadMorePrevButton.classList.add("classHide");
  }
  console.log("TEST");
}, 350);

fetch("/prevlessons", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ clientGroupId: clientGroupId }),
})
  .then((res) => res.json())
  .then((data) => {
    if (data.length >= 5 && !radioNext.checked) {
      loadMorePrevButton.classList.remove("classHide");
    }
    prevLessonArr = data;
    BIGprevLessonArr = data;
    displayAllPrevLesson(data, prevLessonArr.slice(startingIndex, endingIndex));
  })
  .catch((err) => {
    console.log(err);
  });

loadMoreNextButton.addEventListener("click", () => {
  startingIndex += 5;
  endingIndex += 5;
  displayAllNextLesson(
    BIGNextLessonArr,
    NextLessonArr.slice(startingIndex, endingIndex)
  );
  if (NextLessonArr.length <= endingIndex) {
    loadMoreNextButton.classList.add("classHide");
    innerNextLesson.style.marginBottom = "50px";
  }
});

loadMorePrevButton.addEventListener("click", () => {
  startingIndex += 5;
  endingIndex += 5;
  displayAllPrevLesson(
    BIGprevLessonArr,
    prevLessonArr.slice(startingIndex, endingIndex)
  );
  if (prevLessonArr.length <= endingIndex) {
    loadMorePrevButton.classList.add("classHide");
    innerPrevLesson.style.marginBottom = "50px";
  }
});

const displayAllPrevLesson = (lesson, data) => {
  data.forEach(
    (
      {
        lesson_date,
        lesson_name,
        teacher,
        resource_id,
        amount,
        client_valute,
        cost_sale,
      },
      index
    ) => {
      innerPrevLesson.innerHTML += `
    <div class="shedule">
        <div class="scheduleAboutPrev ${index}" id="${resource_id}">
          <h2 class="scheduleDate" id="dateLesson">${lesson_date}</h2>
          <p class="sixe" id="nameTeacher">${teacher}</p>
          <p class="sixe" id="lessonName">${lesson_name}</p>
        </div>
    </div>`;
    }
  );

  const header = document.querySelector(".header");
  const main = document.querySelector(".main");
  const reportAboutLesson = document.querySelector(".reportAboutLesson");
  const backButtonClass = document.querySelector(".backButtonClass");
  const reportAboutData = document.getElementById("reportAboutData");
  const reportAboutDuration = document.getElementById("reportAboutDuration");
  const reportAboutCost = document.getElementById("reportAboutCost");
  const reportAboutLessonName = document.getElementById(
    "reportAboutLessonName"
  );
  const reportAboutTeacher = document.getElementById("reportAboutTeacher");
  const AllscheduleAboutPrev = document.querySelectorAll(".scheduleAboutPrev");
  console.log("nodelist", AllscheduleAboutPrev);

  let valute = "₽";

  for (let i = 0; i < AllscheduleAboutPrev.length; i++) {
    AllscheduleAboutPrev[i].addEventListener("click", () => {
      if (lesson[i].client_valute !== "руб") {
        valute = "€";
      }

      resourceIdFromGet = lesson[i].resource_id;

      fetch("/feadbackstatus", {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
        },
        body: JSON.stringify({ resourseId: resourceIdFromGet }),
      })
        .then((res) => res.json())
        .then((data) => {
          console.log("newdata", data);
          if (data == "200") {
            thanksMess.classList.remove("classHide");
            feadbackForm.classList.add("classHide");
            feadBackContainer.classList.add("classHide");
          } else {
            thanksMess.classList.add("classHide");
            feadbackForm.classList.remove("classHide");
            feadBackContainer.classList.remove("classHide");
          }
        });

      WebApp.BackButton.show();
      header.classList.add("classHide");
      main.classList.add("classHide");
      reportAboutLesson.classList.remove("classHide");
      // feadbackForm.classList.remove("classHide");
      reportAboutData.innerText = `${lesson[i].lesson_date}`;
      reportAboutDuration.innerText = `${lesson[i].amount} мин`;
      reportAboutCost.innerText = `${lesson[i].cost_sale} ${valute}`;
      reportAboutLessonName.innerText = `${lesson[i].lesson_name}`;
      reportAboutTeacher.innerText = `${lesson[i].teacher}`;
      // innerReport.innerText = `${lesson[i].teacher_report}`;
      if (lesson[i].teacher_report === null) {
        reportFromTeacher.innerText =
          "Преподователь еще не успел написать отчет, будет позже";
      } else {
        reportFromTeacher.innerText = `${lesson[i].teacher_report}`;
      }
    });
  }
  WebApp.BackButton.onClick(function () {
    header.classList.remove("classHide");
    main.classList.remove("classHide");
    thanksMess.classList.add("classHide");
    reportAboutLesson.classList.add("classHide");
    feadBackContainer.classList.remove("classHide");
    for (let i = 0; i < allInput.length; i++) {
      allInput[i].checked = false;
    }
    textFeadBackToSend.value = "";
    hidenTextArea.classList.add("classHide");
    optionSlideBarry.classList.add("classHide");
    WebApp.MainButton.hide();
    WebApp.BackButton.hide();
  });
};

const displayAllNextLesson = (lesson, data) => {
  data.forEach(
    (
      {
        lesson_date,
        lesson_name,
        teacher,
        resource_id,
        lesson_date_for_ics,
        lesson_date_for_ics_plus,
        lesson_date_for_js,
        cost_full,
      },
      index
    ) => {
      innerNextLesson.innerHTML += `
    <div class="shedule">

                <div class="scheduleAboutNext">
                    <h2 class="scheduleDate" id="dateLesson">${lesson_date}</h2>
                    <p class="sixe" id="nameTeacher">${teacher}</p>
                    <p class="sixe" id="lessonName">${lesson_name}</p>
                </div>
        
        <div class="scheduleFoo">
          <div class=classCopy id="copy${index}"> 
            <button class="getZoomBtn" id="getZoomBtn${index}">Подключиться к Zoom</button>
            <div class="footerline">
              <img src="/image/scheduleIcon/Group 62.svg" />
              <p class="copyZoom" id="numberCopy${index}">Скопировать ссылку на Zoom</p>
            </div>
            <div class="hrl"></div>
            <div class="footerline">
              <img src="/image/scheduleIcon/clock.svg" />
              <p class="lateLessonButton">Опаздываю на занятие</p>
            </div>
            <div class="hrl"></div>
          </div>
          <div class="footerline">
            <img src="/image/scheduleIcon/calendar3.svg" />
            <p class="addToCalendar">Добавить в календарь</p>
          </div>
          <div class="hrl"></div>
          <div class="footerline">
            <img src="/image/scheduleIcon/clock.svg" />
            <p class="moveLessonButton">Перенести занятие</p>
          </div>
        <div class="hrl"></div>
          <div class="footerline">
            <img src="/image/scheduleIcon/x-lg.svg" />
            <p style="color: #FF513A;" class="cancelLesson">Отменить занятие</p>
          </div>
        </div>
    </div>`;
    }
  );
  displayModalWindow(lesson);
  actionBodyLessonButton(lesson);
};

const lateLesson = (data) => {
  const lateLessonButton = document.querySelectorAll(".lateLessonButton");
  const displayLateLessonPopUp = document.getElementById("lateLessonReferrer");
  const closeLateLesson = document.getElementById("closeLateLesson");
  const closeLatePop = document.getElementById("closeLatePop");
  const sendLateMess = document.getElementById("sendLateMess");

  // const openAlertMessege = document.querySelector(".alertPopUp");
  // const hLessonName = document.getElementById("hLessonName");
  let sendObj = {};

  for (let i = 0; i < lateLessonButton.length; i++) {
    lateLessonButton[i].addEventListener("click", () => {
      sendObj = data[i];
      displayLateLessonPopUp.style.display = "flex";
    });
  }

  sendLateMess.addEventListener("click", () => {
    sendObj["client"] = clientJson;
    fetch("/late-messages", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify(sendObj),
    })
      .then((res) => res.text())
      .then((data) => {
        console.log("смотрум", data);
        showAlert("Сообщение отправленно");
      });
    displayLateLessonPopUp.style.display = "none";
  });

  displayLateLessonPopUp.addEventListener("click", (e) => {
    if (e.target.id === "lateLessonReferrer") {
      displayLateLessonPopUp.style.display = "none";
    }
  });

  closeLatePop.addEventListener("click", () => {
    displayLateLessonPopUp.style.display = "none";
  });

  closeLateLesson.addEventListener("click", () => {
    displayLateLessonPopUp.style.display = "none";
  });
};

// const showAlert = (string) => {
//   const openAlertMessege = document.querySelector(".alertPopUp");

//   openAlertMessege.classList.add("moveClass");
//   openAlertMessege.innerHTML = `
//   <div class="alertContent">
//     <p>${string}</p>
//   </div>`;
//   setTimeout(() => {
//     openAlertMessege.classList.remove("moveClass");
//     setTimeout(() => {
//       openAlertMessege.innerHTML = "";
//     }, 2000);
//   }, 3000);
// };

const moveLesson = (data) => {
  const moveLessonButton = document.querySelectorAll(".moveLessonButton");
  const displayMoveLessonPopUp = document.getElementById("moveLesson");
  const closeMoveLessonBtn = document.getElementById("closeMoveLessonBtn");
  const form = document.getElementById("moveLessonForm");
  const sendFormBtn = document.getElementById("sendFormBtn");
  const hLessonName = document.getElementById("hLessonName");
  let datadata = "";
  for (let i = 0; i < moveLessonButton.length; i++) {
    moveLessonButton[i].addEventListener("click", () => {
      hLessonName.innerText = data[i].lesson_name;
      datadata = data[i];
      displayMoveLessonPopUp.style.display = "flex";
    });
  }

  sendFormBtn.addEventListener("click", (e) => {
    console.log(datadata);
    e.preventDefault();
    let object = {};
    object["lessonName"] = hLessonName.innerText;
    object["requestType"] = "Перенос занятия";
    sendFrom(form, datadata, object);
    setTimeout(() => {
      displayMoveLessonPopUp.style.display = "none";
    });
  });

  closeMoveLessonBtn.addEventListener("click", () => {
    displayMoveLessonPopUp.style.display = "none";
  });

  displayMoveLessonPopUp.addEventListener("click", (e) => {
    if (e.target.id === "moveLesson") {
      displayMoveLessonPopUp.style.display = "none";
    }
  });
};

const sendFrom = (form, bigData, object) => {
  // let object = {};
  let data = new FormData(form);
  data.forEach(function (value, key) {
    object[key] = value;
  });
  // object.push({ Занаятие: nameLessonFromTrial });
  object["bigData"] = bigData;
  // object["clientPhone"] = phoneClient;
  let json = JSON.stringify(object);

  fetch("/api/form", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: json,
  })
    .then((res) => res.text())
    .then((data) => {
      console.log(data);
      if (data == "success") {
        showAlert(
          "Заявка отправлена менеджер свяжется с Вами в ближайшее время"
        );
      } else {
        showAlert("Ошибка попробуйте позднее");
      }
    });
};

let lessonDate = 0;
let nowDate = new Date();
console.log(nowDate);
nowDate = nowDate.getTime();

class GetLessonDate {
  constructor(string) {
    this.string = string;
  }

  returnDate() {
    const match = this.string.match(/-?\d+(\.\d+)?/g);
    let lessonYear = parseInt(match[0]);
    let lessonMount = parseInt(match[1]);
    let lessonDay = parseInt(match[2]);
    let lessonHour = parseInt(match[3]);
    let lessonMinute = parseInt(match[4]);
    let lessonDate = new Date(
      lessonYear,
      lessonMount,
      lessonDay,
      lessonHour,
      lessonMinute
    );
    return lessonDate;
  }
}

// let dateLessonCheckPay = new GetLessonDate("2015, 1, 1, 15, 30").returnDate();
// let dateLessonCheckZoom =

function displayModalWindow(lesson) {
  let valute = "₽";

  const AllcancelLessonButton = document.querySelectorAll(".cancelLesson");
  const AllNextModalButton = document.querySelector(".nextModalButton");

  const AllScheduleDate = document.querySelectorAll(".scheduleDate");
  const innerAnotherDate = document.getElementById("innerAnotherDate");
  const sendCancelData = document.getElementById("cancelLesson");

  const secondModal = document.getElementById("secondModal");
  const thirdModal = document.getElementById("thirdModal");
  const payCancel = document.getElementById("payFullCancel");
  const headCloseModalButton1 = document.getElementById("closeBtn1");
  const headCloseModalButton2 = document.getElementById("closeBtn2");
  const bodyCloseModalButton = document.querySelector(".close");

  const takeAllCopyClass = document.querySelectorAll(".classCopy");
  const takeAllScheduleClass = document.querySelectorAll(".shedule");

  console.log("дата урока", lesson);

  const modal = document.getElementById("referrer");

  for (let i = 0; i < AllcancelLessonButton.length; i++) {
    if (lesson[i].client_valute !== "руб") {
      valute = "€";
    }

    let dateLessonCheckZoom = new GetLessonDate(
      lesson[i].lesson_date_for_js
    ).returnDate();

    dateLessonCheckZoom.setHours(dateLessonCheckZoom.getHours() - 2);
    console.log(dateLessonCheckZoom);
    const comparseDate = dateLessonCheckZoom.getTime();
    if (nowDate <= comparseDate) {
      // console.log("hide",hideCopy[i])
      takeAllCopyClass[i].classList.add("classHide");
    }

    AllcancelLessonButton[i].addEventListener("click", () => {
      const resourceId = lesson[i].resource_id;

      getTextCancelLesson(resourceId, payCancel);

      setTimeout(() => {
        modal.style.display = "flex";
        secondModal.classList.remove("classHide");
      }, 400);

      AllNextModalButton.addEventListener("click", () => {
        innerAnotherDate.innerText = `Занятие «${AllScheduleDate[i].innerText}» успешно отменено`;
        getActionCancelLesson(resourceId, innerAnotherDate);

        setTimeout(() => {
          // innerAnotherDate.innerText = `Занятие «${AllScheduleDate[i].innerText}» успешно отменено`;
          secondModal.classList.add("classHide");
          thirdModal.classList.remove("classHide");
        }, 650);
      });

      headCloseModalButton1.addEventListener("click", closeModal);

      headCloseModalButton2.addEventListener("click", () => {
        if (flagActionCancelLesson) {
          takeAllScheduleClass[i].style.display = "none";
        }
        closeModal();
      });

      sendCancelData.addEventListener("click", () => {
        if (flagActionCancelLesson) {
          takeAllScheduleClass[i].style.display = "none";
        }
        closeModal();
      });

      bodyCloseModalButton.addEventListener("click", closeModal);
    });

    modal.addEventListener("click", (e) => {
      if (
        e.target.id === "referrer" &&
        thirdModal.classList[1] === "classHide"
      ) {
        closeModal();
      }
    });

    function closeModal() {
      modal.style.display = "none";
      secondModal.classList.add("classHide");
      thirdModal.classList.add("classHide");
    }
  }
}

function getTextCancelLesson(req, string) {
  fetch("/cancellesson/text", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      resourceId: req,
    }),
  })
    .then((res) => res.text())
    .then((data) => {
      string.innerHTML = data.slice(1, data.length - 1);
      console.log("что", data);
    })
    .catch((err) => {
      console.log(err);
    });
}

function getActionCancelLesson(req, string) {
  fetch("/cancellesson/action", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      resourceId: req,
    }),
  })
    .then((res) => res.json())
    .then((data) => {
      console.log(data);
      if (data != "204") {
        console.log("error");
        string.innerText = "Возникла ошибка, попробуйте позднее";
        flagActionCancelLesson = false;
      }
    })
    .catch((err) => {
      console.log(err);
    });
}

if (radioPrev !== null && radioNext !== null) {
  // if (radioNext.checked){

  // }
  console.log("radio", radioNext.checked);
  radioPrev.addEventListener("click", () => {
    if (BIGprevLessonArr.length >= 5) {
      loadMorePrevButton.classList.remove("classHide");
    }
    // loadMorePrevButton.classList.remove("classHide");
    loadMoreNextButton.classList.add("classHide");
    innerNextLesson.classList.add("classHide");
    innerPrevLesson.classList.remove("classHide");
  });
  radioNext.addEventListener("click", () => {
    if (BIGNextLessonArr.length >= 5) {
      loadMoreNextButton.classList.remove("classHide");
    }
    loadMorePrevButton.classList.add("classHide");
    innerPrevLesson.classList.add("classHide");
    innerNextLesson.classList.remove("classHide");
  });
}

function actionBodyLessonButton(lesson) {
  // const firstLesson = document.getElementById("numberCopy0");
  // const firstButtonToZoom = document.getElementById("getZoomBtn0");

  const allCopyZoomurl = document.querySelectorAll(".copyZoom");
  const allGetZoom = document.querySelectorAll(".getZoomBtn");

  const addToCalendarAll = document.querySelectorAll(".addToCalendar");
  const calendarPopUP = document.getElementById("firstReferrer");
  const googleButton = document.getElementById("googleButton");
  const yandexButton = document.getElementById("yandexButton");

  const closeCalendarButton = document.getElementById("closeCalendarButton");

  for (let i = 0; i < addToCalendarAll.length; i++) {
    let urlfFromCalendar = `http://www.google.com/calendar/event?action=TEMPLATE&text=${lesson[i].lesson_name}&dates=${lesson[i].lesson_date_for_ics}/${lesson[i].lesson_date_for_ics_plus}&details=${lesson[i].zoom_url}&location=test&crm=AVAILABLE`;
    let urlYandex = `https://calendar.yandex.ru/week/create?startTs=${lesson[i].lesson_date_for_ics}&endTs=${lesson[i].lesson_date_for_ics_plus}&name=${lesson[i].lesson_name}&description=${lesson[i].zoom_url}`;

    addToCalendarAll[i].addEventListener("click", () => {
      calendarPopUP.style.display = "flex";

      googleButton.addEventListener("click", () => {
        window.open(urlfFromCalendar, "_blank", "noopener");
        calendarPopUP.style.display = "none";
      });

      yandexButton.addEventListener("click", () => {
        window.open(urlYandex, "_blank", "noopener");
        calendarPopUP.style.display = "none";
      });
    });

    allGetZoom[i].addEventListener("click", () => {
      window.open(lesson[i].zoom_url, "_blank", "noopener");
    });

    allCopyZoomurl[i].addEventListener("click", function () {
      navigator.clipboard
        .writeText(lesson[i].zoom_url)
        .then(function () {
          showAlert("Скопированно");
        })
        .catch(function (error) {
          console.error("Error:", error);
        });
    });
  }

  closeCalendarButton.addEventListener("click", () => {
    calendarPopUP.style.display = "none";
  });

  calendarPopUP.addEventListener("click", (e) => {
    if (e.target.id === "firstReferrer") {
      calendarPopUP.style.display = "none";
    }
  });
}

const hidenTextArea = document.getElementById("textArea");
const AllStars = document.querySelectorAll(".allRadio");
const allInput = document.querySelectorAll(".allInput");
const textFeadBackToSend = document.getElementById("textFeadBack");
const feadbackForm = document.getElementById("feadbackForm");
const thanksMess = document.querySelector(".thanks");
// const innerReport = document.getElementById("innerReport");
const showTeacherReport = document.getElementById("showTeacherReport");
const firstStar = document.getElementById("star1");
const feadBackContainer = document.getElementById("feadBackContainer");
const optionSlideBarry = document.querySelector(".favor");

const showTeacherReportPopUp = document.getElementById("secondReferrer");
const reportFromTeacher = document.getElementById("reportFromTeacher");
const closeReportTeacherButton = document.getElementById(
  "closeReportTeacherButton"
);

console.log(optionSlideBarry);

let sendFeadBackRating = 0;

showTeacherReport.addEventListener("click", () => {
  // innerReport.classList.remove("classHide");
  showTeacherReportPopUp.style.display = "flex";
});

showTeacherReportPopUp.addEventListener("click", (e) => {
  if (e.target.id === "secondReferrer") {
    showTeacherReportPopUp.style.display = "none";
  }
});

closeReportTeacherButton.addEventListener("click", () => {
  showTeacherReportPopUp.style.display = "none";
});

for (let i = 0; i < AllStars.length; i++) {
  AllStars[i].addEventListener("click", () => {
    hidenTextArea.classList.remove("classHide");
    optionSlideBarry.classList.remove("classHide");
    sendFeadBackRating = allInput[i].value;
    // console.log(sendFeadBackRating);

    setTimeout(() => {
      window.scrollBy(0, 300);
    }, 150);
    WebApp.MainButton.show();
  });
}

const sendButton = document.getElementById("testingRemotse");
let j = 0;
sendButton.addEventListener("click", (e) => {
  e.preventDefault();

  let checkBoxData = {};
  let data = new FormData(feadbackForm);
  console.log("это форма", data);
  data.forEach(function (value, key) {
    checkBoxData[key] = value;
  });

  checkBoxData.resource_id = resourceIdFromGet;

  postData("/sendfeadback", checkBoxData).then((data) => {
    console.log(data); // JSON data parsed by `response.json()` call
  });
});

async function postData(url = "", data = {}) {
  // Default options are marked with *
  const response = await fetch(url, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify(data),
  }).catch(function (error) {
    console.error("Error:", error);
  });
  return await response.text();
}

WebApp.MainButton.onClick(function () {
  if (textFeadBackToSend.value.length < 1) {
    textFeadBackToSend.placeholder = "Не забудьте заполнить отзыв";
  } else {
    const sendUrl = `https://crm.caremybaby.ru/Remotes/bot__getdata_jdDr41n?request=new_feedback&feedback_mark=${sendFeadBackRating}&feedback_text=${textFeadBackToSend.value}&resource_id=${resourceIdFromGet}`;
    // const testResponse = `https://crm.caremybaby.ru/Remotes/twga__pc_test_feadback-aefFAW3q4?feedback_mark=${sendFeadBackRating}&feedback_text=${textFeadBackToSend.value}&resource_id=${resourceIdFromGet}&${checkBoxData[0].name}=${checkBoxData[0].value}`;

    let checkBoxData = {};
    let data = new FormData(feadbackForm);
    console.log("это форма", data);
    data.forEach(function (value, key) {
      checkBoxData[key] = value;
    });

    checkBoxData.resource_id = resourceIdFromGet;

    postData("/sendfeadback", checkBoxData).then((data) => {
      console.log(data); // JSON data parsed by `response.json()` call
    });

    // fetch(sendUrl)
    //   .then((res) => res.json())
    //   .then((data) => {
    //     console.log(data);
    //   })
    //   .catch((err) => {
    //     console.log(err);
    //   });
    WebApp.MainButton.hide();
    feadbackForm.classList.add("classHide");
    hidenTextArea.classList.add("classHide");
    optionSlideBarry.classList.add("classHide");
    thanksMess.classList.remove("classHide");
    feadBackContainer.classList.add("classHide");
  }

  // реализация отправки рейтинга и отзыва
});

autosize(document.getElementById("textFeadBack"));

const dateqwerw = () => {
  const form = new FormData(document.getElementById("form"));
};
